import koa from './lib/koa.js'
import router from './router/index.js'
import wss from './lib/ws/server.js'
import ws from './lib/ws/client.js'

import md5 from './utils/md5.js'
import fs from 'fs/promises'
import dayjs from 'dayjs'

class App {
  constructor() {
    this.app = koa({
      router,
      uses: [],
      port: 1200,
    })

    this.wsInit()
  }

  wsInit() {
    // wss({
    //   port: 8765,
    // })
    let index = 1

    ws({
      address: 'ws://10.254.32.20:8765',
      onMessage(message) {
        const filename = `data/${index++}.txt`
        fs.writeFile(filename, message, 'utf-8')
      },
    })
  }
}

new App()
